//logs.js
const util = require('../../utils/util.js')
import request from "../../utils/request";
var api = require("../../utils/api");

Page({
  data: {
    noData: false,
    page: 1,// 第几页
    resultContent: '',
    loading: false,
    access_token: '354c3be6ced8dea9d0d9296a0add28fb',
    cellData: [],
    listType: 0,
    stateArr: [{
      name: '',
      className: '',
      textClass: ''
    }, {
      name: '待处理',
      className: 'back-blue',
      textClass: 'blue'
    },
    {
      name: '待处理',
      className: 'back-green',
      textClass: 'green'
    },
    {
      name: '已处理',
      className: 'back-yellow',
      textClass: 'yellow'
    },
    {
      name: '处理中',
      className: 'back-green',
      textClass: 'green'
    }, {
      name: '已处理',
      className: 'back-red',
      textClass: 'red'
    }, {
      name: '已奖励',
      className: 'back-red',
      textClass: 'red'
    }
    ],
  },

  onLoad() {
    this.fetchData()
  },
  onShow() {
    
  },
  onCell(e){
    var cellId = e.currentTarget.dataset.cellid
    wx.navigateTo({
      url: '/pages/newsList/newDetail/newDetail?cellId=' + cellId,
    })
  },
  // 下拉事件
  onPullDownRefresh() {
    var curPage = this.data.page
    // 待测试

    if (this.data.page > 1) {
      this.setData({
        page: curPage - 1
      })
    }
    this.fetchData()
  },
  //上啦触底
  onReachBottom: function () {
    let page = this.data.page
    this.setData({
      page: page + 1,
    })
    this.fetchData()
  },
  fetchData() {
    var url = api.SecretArticlelist
    var self = this
    var params = {
      list_rows: 10,
      page: this.data.page
    }
    request(url, params, "POST").then(res => {
      if (res.code == 0) {
        if (res.data.data.length <= 0) {
          wx: wx.showToast({
            title: '无更多数据',
            icon: 'none',
          })
          this.setData({
            noData: true
          })
        }
        var result = []
        if (this.data.page > 1) {
          result = self.data.cellData.concat(res.data.data);
        } else {
          result = res.data.data
        }
        if (this.data.page > 1 && res.data.data.length <= 0) {
          this.setData({
            page: this.data.page - 1
          })
        }
        result.forEach(item =>{
          item.create_time =  item.create_time.slice(0,10)
        })
        this.setData({
          cellData: result
        })
      }
    })
  }
})